package cn.source.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import cn.source.common.annotation.Log;
import cn.source.common.core.controller.BaseController;
import cn.source.common.core.domain.AjaxResult;
import cn.source.common.enums.BusinessType;
import cn.source.system.domain.TravelBabel;
import cn.source.system.service.ITravelBabelService;
import cn.source.common.utils.poi.ExcelUtil;
import cn.source.common.core.page.TableDataInfo;

/**
 * 标签管理Controller
 *
 * @author sourcebyte.vip
 * @date 2024-06-18
 */
@RestController
@RequestMapping("/travel/babel")
public class TravelBabelController extends BaseController
{
    @Autowired
    private ITravelBabelService travelBabelService;

    /**
     * 查询标签管理列表
     */
    @PreAuthorize("@ss.hasPermi('travel:babel:list')")
    @GetMapping("/list")
    public TableDataInfo list(TravelBabel travelBabel)
    {
        startPage();
        List<TravelBabel> list = travelBabelService.selectTravelBabelList(travelBabel);
        return getDataTable(list);
    }

    /**
     * 获取标签管理详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(travelBabelService.selectTravelBabelById(id));
    }

    /**
     * 新增标签管理
     */
    @PreAuthorize("@ss.hasPermi('travel:babel:add')")
    @Log(title = "标签管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TravelBabel travelBabel)
    {
        return toAjax(travelBabelService.insertTravelBabel(travelBabel));
    }

    /**
     * 修改标签管理
     */
    @PreAuthorize("@ss.hasPermi('travel:babel:edit')")
    @Log(title = "标签管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TravelBabel travelBabel)
    {
        return toAjax(travelBabelService.updateTravelBabel(travelBabel));
    }

    /**
     * 删除标签管理
     */
    @PreAuthorize("@ss.hasPermi('travel:babel:remove')")
    @Log(title = "标签管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(travelBabelService.deleteTravelBabelByIds(ids));
    }

    /**
     * 导出标签管理列表
     */
    @PreAuthorize("@ss.hasPermi('travel:babel:export')")
    @Log(title = "标签管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TravelBabel travelBabel)
    {
        List<TravelBabel> list = travelBabelService.selectTravelBabelList(travelBabel);
        ExcelUtil<TravelBabel> util = new ExcelUtil<TravelBabel>(TravelBabel.class);
        util.exportExcel(response, list, "标签管理数据");
    }
}
